﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibMinecraft.Server;
using LibMinecraft.Model;

namespace PartyCraftServer.Commands
{
    public class GameModeCommand : Command
    {
        public override bool RequiresOp
        {
            get { return true; }
        }

        public override string DefaultCommand
        {
            get { return "gamemode"; }
        }

        public override string Documentation
        {
            get { return "Changes a player's game mode.\nUsage: /gamemode [player] [survival|creative|0|1]"; }
        }

        public override void ExecuteCommand(RemoteClient client, params string[] parameters)
        {
            if (parameters.Length != 2)
            {
                client.SendChat(ChatColor.Red + "Invalid parameters.  Use /gamemode [player] [survival|creative|0|1]");
                return;
            }
            if (parameters[1].ToLower() != "survival" && parameters[1].ToLower() != "creative" &&
                parameters[1].ToLower() != "0" && parameters[1].ToLower() != "1")
            {
                client.SendChat(ChatColor.Red + "Invalid parameters.  Use /gamemode [player] [survival|creative|0|1]");
                return;
            }
            bool creative = parameters[1].ToLower() == "creative" || parameters[1].ToLower() == "1";
            PartyCraft.Server.GetClient(parameters[0]).PlayerEntity.GameMode =
                creative ? GameMode.Creative : GameMode.Survival;
        }
    }
}
